package com.cloud.system.controller;

import com.cloud.common.domain.Result;
import com.cloud.system.entity.SysAxis;
import com.cloud.system.service.ISysAxisService;
import com.cloud.utils.ExcelPoiUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.ArrayList;
import java.util.List;

@Tag(name = "坐标转换工具")
@RestController
@RequestMapping("/system/axis")
public class SysAxisController {

    @Autowired
    private ISysAxisService sysAxisService;

    @Operation(summary = "坐标类型转换")
    @PostMapping("/invertAxis")
    public Result invertAxis(@RequestBody SysAxis axis) {
        return sysAxisService.invertAxis(axis);
    }

    @Operation(summary = "下载模板")
    @GetMapping("/template")
    public void template(HttpServletResponse response) {
        String titleName = "坐标转换模板";
        List<SysAxis> userList = new ArrayList<>();
        ExcelPoiUtils.exportExcel(userList, titleName, "坐标", SysAxis.class,
                titleName + ".xls", response);
    }

    @Operation(summary = "根据Excel模板信息导入数据")
    @PostMapping("/importExcel")
    public Result importData(@RequestParam("file") MultipartFile file) {
        return Result.success("操作成功", sysAxisService.importExcel(file));
    }

    @Operation(summary = "根据Excel模板信息导出数据")
    @PostMapping("/exportExcel")
    public void export(@RequestBody List<SysAxis> axisList) {
        sysAxisService.exportExcel(axisList);
    }

    @Operation(summary = "根据Json信息导入数据")
    @PostMapping("/importJson")
    public Result importJson(@RequestParam("putAxis") Integer putAxis,
                             @RequestParam("outAxis") Integer outAxis,
                             @RequestParam("file") MultipartFile file) {
        return sysAxisService.importJson(putAxis, outAxis, file);
    }

    @Operation(summary = "根据Json信息导出数据")
    @PostMapping("/exportJson")
    public void exportJson(@RequestBody String geojson) {
        sysAxisService.exportJson(geojson);
    }

}
